/*
 * @Descripttion: 动态加载页面数据
 * @version: 1.0.0
 * @Author: liuchenguang
 * @Date: 2022-4-2
 */

import { validateNull } from '@tapui/utils/validate'

const dynamicSubPage = {
  state: {
    // 是否要打开动态页面
    isOpenDynamicSubPage: false,
    // 动态页面组件参数
    dynamicSubPageParams: {}
  },
  getters: {
    isOpenDynamicSubPage: (state) => state.isOpenDynamicSubPage,
    dynamicSubPageParams: (state) => state.dynamicSubPageParams
  },
  mutations: {
    SET_IS_OPEN_DYNAMIC_SUB_PAGE: (state, isOpenDynamicSubPage) => {
      state.isOpenDynamicSubPage = isOpenDynamicSubPage
    },
    SET_DYNAMIC_SUB_PAGE_PARAMS: (state, dynamicSubPageParams) => {
      state.dynamicSubPageParams = dynamicSubPageParams
    }
  },
  actions: {
    /** 改变动态加载页面 */
    changeDynamicSubPage({ commit }, { isOpenDynamicSubPage, ...dynamicSubPageParams }) {
      console.log(arguments)
      commit('SET_IS_OPEN_DYNAMIC_SUB_PAGE', isOpenDynamicSubPage)
      if (!validateNull(dynamicSubPageParams)) {
        commit('SET_DYNAMIC_SUB_PAGE_PARAMS', dynamicSubPageParams)
      }
    }
  }
}
export default dynamicSubPage
